$(function() {

    $('.side-menu>dl>dt').click(function() {
        $(this).next('dd').slideToggle(300)
    })
    let dataArr = JSON.parse(localStorage.getItem('tempDatas'));
    console.log(dataArr);
    let rels = '';
    if (dataArr) {
        dataArr.forEach((item, i) => {
            rels += `
            <li>
                <div class="coll-goods">
                    <div class="p-img">
                        <a href="javascript:void(0)">
                            <img src="${item.imgUrl}" alt="">
                        </a>
                    </div>
                    <div class="p-name">
                        <a href="javascript:void(0)" target="_blank" title="测试">${item.titles}</a>
                    </div>
                    <div class="p-price"> ¥${item.prices} </div>
                    <div class="p-btn">
                        <a href="./details.html#${item.id}${item.pageName}/${item.dataName}" class="sc-btn">查看详情</a>
                    </div>
                    <div class="p-oper">
                        <a href="javascript:void(0)" class="goods_gz">关注商品</a>
                        <a href="javascript:void(0)" class="remove" data-id=${i}>取消收藏</a>
                    </div>
                </div>
            </li>
            `;
        });
    }
    $('.list-ul').html('');


    if (!$('.list-ul')[0].children.length) {
        $('.no_records').show();
    } else {
        $('.no_records').hide();
    }


    $('.list-ul').html(rels);
    if (!$('.list-ul')[0].children.length) {
        $('.no_records').show();
    } else {
        $('.no_records').hide();
    }
    $('.remove').click(function() {
        $(this).parents('li').remove();
        dataArr.splice(this.dataset.id, 1);
        if (!dataArr.length) {
            localStorage.removeItem('tempDatas');
        }
        localStorage.setItem('tempDatas', JSON.stringify(dataArr));

        if (!$('.list-ul')[0].children.length) {
            $('.no_records').show();
        } else {
            $('.no_records').hide();
        }

    });
});